<template>
    <div class="pro-container">
        <better-scroll
            ref="scroll"
            class="scroll-t"
            :refresh="initDataList"
            :onLoading="loadDataList"
            :isCategory="false">
            <div class="pro-goods-items flex-row plr15">
                <div class="pro-goods-item" v-for="(item, index) in loadData"
                     @click="$router.push({name:'goods-detail',query:{id:item.id}})">
                    <img class="pro-goods-pic" :src="item.img" alt="">
                    <div class="pro-goods-main">
                        <h4 class="pro-goods-title row1">{{item.name}}</h4>
                        <p class="pro-goods-info">
                                <span class="pro-goods-price">¥{{computePrice(item.price)}}
                                    <s class="pro-goods-o_price">¥{{computePrice(item.old_price)}}</s></span>
                            <span class="pro-goods-sale">销量 {{item.sale_num}}</span>
                        </p>
                    </div>
                </div>
            </div>
        </better-scroll>
    </div>
</template>

<script>
    export default {
        name: "PromotionList",
        data() {
            return {
                params: {offset: 0, len: 10}
            }
        },
        beforeRouteEnter(to, from, next) {
            next(vm => {
                if (from.name !== 'goods-detail') vm.initDataList()

            })
        },
        methods: {
            initParams() {
                this.params.offset = 0
                this.loadData = []
            },
            initDataList() {
                this.initParams()
                this.loadDataList()
            },
            loadDataList() {
                this.pubilcInitDataList('PRO_GOODS_LIST', this.params)
            },
        }
    }
</script>

<style scoped lang="scss">
    .pro-goods-items {
        flex-wrap: wrap;
    }

    .pro-goods-item {
        display: flex;
        align-items: center;
        flex-direction: column;
        width: 165px;
        height: 230px;
        margin-top: 10px;
        background: #fff;
        padding: 0 10px;
        border-radius: 5px;
        .pro-goods-pic {
            width: 165px;
            height: 165px;
            border-top-left-radius: 5px;
            border-top-right-radius: 5px;
            margin-bottom: 5px;
        }
        .pro-goods-main {
            .pro-goods-title {
                font-size: 13px;
            }
            .pro-goods-info {
                font-size: 12px;
                .pro-goods-price {
                    display: flex;
                    align-items: flex-end;
                    line-height: 1.2;
                    font-size: 14px;
                    margin: 3px 0;
                    color: $theme-color;
                    .pro-goods-o_price {
                        margin-left: 5px;
                        font-size: 12px;
                        color: #999;
                    }
                }
            }
        }
    }
</style>
